package com.trussell.genesis.windowutils.menus;

import java.awt.event.InputEvent;

import javax.swing.ImageIcon;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

import com.trussell.genesis.windowutils.listeners.NewWorldActionListener;
import com.trussell.genesis.windowutils.listeners.SelectWorkspaceActionListener;

/**
 * This class helps reduce the number of lines of code
 * in Genesis.java by taking the GUI and controller 
 * construction of the File menu and placing it into
 * this class.
 * @author Tyler Trussell
 */
public class FileMenu extends JMenu
{
	private static final long serialVersionUID = 1L;

	/**
	 * Returns a GenesisFileMenu, which contains the prepared
	 * JMenuItems necessary. They have already been bound to
	 * listeners.
	 */
	public FileMenu() {
		super("File");
		
		JMenuItem selWorkspace = new JMenuItem("Select Workspace...");
		selWorkspace.setAccelerator(KeyStroke.getKeyStroke('W', InputEvent.CTRL_MASK));
		JMenuItem newWorld = new JMenuItem("New World...");
		newWorld.setAccelerator(KeyStroke.getKeyStroke('N', InputEvent.CTRL_MASK));
		JMenuItem openWorld = new JMenuItem("Open World...");
		openWorld.setAccelerator(KeyStroke.getKeyStroke('O', InputEvent.CTRL_MASK));
		JMenuItem saveWorld = new JMenuItem("Save World");
		saveWorld.setAccelerator(KeyStroke.getKeyStroke('S', InputEvent.CTRL_MASK));
		JMenuItem saveWorldAs = new JMenuItem("Save World As...");
		saveWorldAs.setAccelerator(KeyStroke.getKeyStroke('S', InputEvent.CTRL_MASK + InputEvent.SHIFT_MASK));
		JMenuItem exportWorldToJar = new JMenuItem("Export for Game Engine...");
		exportWorldToJar.setAccelerator(KeyStroke.getKeyStroke('E', InputEvent.CTRL_MASK));
		JMenuItem closeWorld = new JMenuItem("Close World");
		closeWorld.setAccelerator(KeyStroke.getKeyStroke('C', InputEvent.ALT_MASK));
		JMenuItem exit = new JMenuItem("Exit");
		exit.setAccelerator(KeyStroke.getKeyStroke('Q', InputEvent.ALT_MASK));
		JMenuItem importAssets = new JMenuItem("Import Assets...");
		importAssets.setAccelerator(KeyStroke.getKeyStroke('I', InputEvent.CTRL_MASK));
		
		selWorkspace.setIcon(new ImageIcon("images/basicicons/Preferences16.gif"));
		newWorld.setIcon(new ImageIcon("images/basicicons/Add16.gif"));
		openWorld.setIcon(new ImageIcon("images/basicicons/Open16.gif"));
		saveWorld.setIcon(new ImageIcon("images/basicicons/Save16.gif"));
		saveWorldAs.setIcon(new ImageIcon("images/basicicons/SaveAs16.gif"));
		exportWorldToJar.setIcon(new ImageIcon("images/basicicons/Export16.gif"));
		closeWorld.setIcon(new ImageIcon("images/basicicons/Close16.gif"));
		exit.setIcon(new ImageIcon("images/basicicons/Exit16.gif"));
		importAssets.setIcon(new ImageIcon("images/basicicons/Import16.gif"));
		
		newWorld.addActionListener(new NewWorldActionListener());
		selWorkspace.addActionListener(new SelectWorkspaceActionListener());

		add(selWorkspace);
		addSeparator();
		add(newWorld);
		add(openWorld);
		addSeparator();
		add(importAssets);
		addSeparator();
		add(saveWorld);
		add(saveWorldAs);
		add(exportWorldToJar);
		addSeparator();
		add(closeWorld);
		add(exit);
	}
}
